
package com.jy.framework.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.jy.framework.constant.RStrtusEnum;

/**
 * 返回数据
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年10月27日 下午9:59:27
 */
public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	public static final String CODE = "code";
	public static final String MSG = "msg";
	public static final String DATA = "data";
	public static final String SUCCESS = "success";
	public static final String DEBUGMSG = "debugMsg";
	

	public R() {
		put(CODE, RStrtusEnum.SUCCESS.getCode());
		put(MSG, RStrtusEnum.SUCCESS.getValue());
		put(SUCCESS, true);
		put(DEBUGMSG, null);
	}
	
	public static R error() {
		return error(RStrtusEnum.ERROR.getCode(), RStrtusEnum.ERROR.getValue(),null);
	}
	
	public static R error(String msg) {
		return error(RStrtusEnum.ERROR.getCode(), msg,null);
	}
	
	public static R error(String msg,String debugmsg) {
		return error(RStrtusEnum.ERROR.getCode(), msg,debugmsg);
	} 

	public static R error(int code, String msg) {
		return error(code, msg, null);
	}
	
	public static R error(int code, String msg,String debugmsg) {
		R r = new R();
		r.put(CODE, code);
		r.put(MSG, msg);
		r.put(SUCCESS, false);
		r.put(DEBUGMSG, debugmsg);
		return r;
	}

	public static R ok(String msg) {
		R r = new R();
		r.put(MSG, msg);
		r.put(SUCCESS, true);
		r.put(DEBUGMSG, msg);
		return r;
	}
	
	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}
	
	public static R ok() {
		return new R();
	}
	public static String genUUID() {
		return UUID.randomUUID().toString().replaceAll("-+", "");
	}
	@Override
	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
